<?php defined('BASEPATH') OR exit('No direct script access allowed');

	class obgyne_directory_class extends CI_Model {
	
		public function list_obgyne_directory(){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$this->db->order_by("strName", "asc");
				$query = $this->db->get_where('jtn_obgyne_directory',array('intDisabled'=>0,'intID'=>$intID));
			} else {
				$this->db->order_by("strName", "asc");
				$query = $this->db->get_where('jtn_obgyne_directory',array('intDisabled'=>0));
			}
			if ($query->num_rows() > 0){
				$result = $query->result_array();
				return $result;
			}
			else{
				return 0;
			}
		}
		public function get_obgyne_dir($post){
			$intID=0;
			if(isset($post['intID'])){
				$intID = $post['intID'];
			}
			$intID = stripslashes(filter_var($intID, FILTER_SANITIZE_STRING));
			$query = $this->db->get_where('jtn_obgyne_directory',array('intID'=>$intID))->result_array();
			$query = current($query);
		
			if(trim($query['intID'])=="") {
				return 0;
			} else {
				return $query;
			}
		}
		public function update($post){
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
			$strName = stripslashes(filter_var($post['strName'], FILTER_SANITIZE_STRING));
			$strSalutation = stripslashes(filter_var($post['strSalutation'], FILTER_SANITIZE_STRING));
			
			$strIntUserID = stripslashes(filter_var($post['intOBDirectoryID'], FILTER_SANITIZE_STRING));
			$strLocation = stripslashes(filter_var($post['strLocation'], FILTER_SANITIZE_STRING));
			$strDays = stripslashes(filter_var($post['strDays'], FILTER_SANITIZE_STRING));
			$timeSpan = stripslashes(filter_var($post['timeSpan'], FILTER_SANITIZE_STRING));
			
			$data = array(
					'strSalutation' => $strSalutation,
					'strName' => $strName,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
			$data2 = array(
					'strLocation'=>$strLocation,
					'strDays'=>$strDays,
					'strTime'=>$timeSpan,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);

			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_obgyne_directory', $data);
			
			$this->db->where(array('intOBDirectoryID'=>$strIntUserID));
			$this->db->update('jtn_obgyne_directory_info', $data2);
			//$message['qry']=$this->db->last_query();
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
		public function delete($post){
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));	
		
			$data = array(
					'intDisabled' => 1,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
				
			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_obgyne_directory', $data);
				
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
		public function insert($post){
			$strName = stripslashes(filter_var($post['strName'], FILTER_SANITIZE_STRING));
			$strSalutation = stripslashes(filter_var($post['strSalutation'], FILTER_SANITIZE_STRING));
			
			$strLocation = stripslashes(filter_var($post['strLocation'], FILTER_SANITIZE_STRING));
			$strDays = stripslashes(filter_var($post['strDays'], FILTER_SANITIZE_STRING));
			$timeSpan = stripslashes(filter_var($post['timeSpan'], FILTER_SANITIZE_STRING));
					
			$data = array(
					'intUserID' => $this->session->userdata('intID'),
					'strSalutation' => $strSalutation,
					'strName' => $strName,
					'intDisabled' => 0,
					'strCreatedby'=>$this->session->userdata('intID'),
					'dateCreatedDate'=>date('Y-m-d H:i:s'),
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);

			$this->db->insert('jtn_obgyne_directory', $data);
			$data2 = array(
					'intOBDirectoryID' => $this->db->insert_id(),
					'strLocation' => $strLocation,
					'strDays'=>$strDays,
					'strTime'=>$timeSpan,
					'intDisabled' => 0,
					'strCreatedby'=>$this->session->userdata('intID'),
					'dateCreatedDate'=>date('Y-m-d H:i:s'),
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
			$this->db->insert('jtn_obgyne_directory_info', $data2);
			//$message['qry']=$this->db->last_query();
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
	} // end class
?>